//
//  EFGoodsDetailViewCellPrice.m
//  EnjogFood
//
//  Created by guocheng on 2017/5/21.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFGoodsDetailViewCellPrice.h"
#import "EFGoodsDetailViewItemPrice.h"

@interface EFGoodsDetailViewCellPrice()

@property(strong,nonatomic)UILabel* priceLabel;
@property(strong,nonatomic)UILabel* salePriceLabel;
@property(strong,nonatomic)UILabel* soldLabel;
@property(strong,nonatomic)UIView* lineView;


@end

@implementation EFGoodsDetailViewCellPrice



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor clearColor];
        self.backgroundColor = [UIColor whiteColor];
        [self initView];
    }
    return self;
}

-(void)setObject:(EFGoodsDetailViewItemPrice *)item{
    
    [self.priceLabel setText:[NSString stringWithFormat:@"¥%@",item.salePrice]];
    [self.priceLabel sizeToFit];
    
    //中划线
    NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};;
    NSString* strSalePrice = [NSString stringWithFormat:@"¥%@",item.price];
    NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:strSalePrice attributes:attribtDic];
    self.salePriceLabel.attributedText = attribtStr;
    [self.salePriceLabel sizeToFit];
    self.salePriceLabel.left = self.priceLabel.right + 10;
    
    [self.soldLabel setText:[NSString stringWithFormat:@"已售%@",item.sold]];
    [self.soldLabel sizeToFit];
    
    self.soldLabel.left = kScreenWidth - self.soldLabel.width - 20;
    
    self.lineView.top = self.priceLabel.bottom + 16;
}

-(void)initView{
    [self.contentView addSubview:self.priceLabel];
    [self.contentView addSubview:self.salePriceLabel];
    [self.contentView addSubview:self.soldLabel];
   //[self.contentView addSubview:self.lineView];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.priceLabel.top = 10;
    self.priceLabel.left = 20;
    
    self.salePriceLabel.top = 10;
    
    self.soldLabel.top = 10;
    
    //self.lineView.left = 20;
}

-(UILabel *)priceLabel{
    if(_priceLabel == NULL){
        _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 47, 13)];
        _priceLabel.font = [UIFont systemFontOfSize:13];
        _priceLabel.textColor  = RGBCOLOR(0x69BA45);
        _priceLabel.left = 20;
    }
    return _priceLabel;
}

-(UILabel *)salePriceLabel{
    if(_salePriceLabel == NULL){
        _salePriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 47, 13)];
        _salePriceLabel.font = [UIFont systemFontOfSize:13];
        _salePriceLabel.textColor  = RGBCOLOR(0xCCCCCC);
        _salePriceLabel.left = 20;
    }
    return _salePriceLabel;
}

-(UILabel *)soldLabel{
    if(_soldLabel == NULL){
        _soldLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 47, 13)];
        _soldLabel.font = [UIFont systemFontOfSize:13];
        _soldLabel.textColor  = RGBCOLOR(0xCCCCCC);
        _soldLabel.left = 20;
    }
    return _soldLabel;
}


-(UIView*)lineView{
    if(_lineView == NULL){
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth - 40, 1)];
        _lineView.backgroundColor = kBlackDDD;
        
    }
    return _lineView;
}



@end
